<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@page isELIgnored="false" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>补贴设置</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link id="bootstrap-style" href="<c:url value="/css/bootstrap.min.css"/>" rel="stylesheet">
	<link href="<c:url value="/css/bootstrap-responsive.min.css"/>" rel="stylesheet">
	<link id="base-style" href="<c:url value="/css/style.css"/>" rel="stylesheet">
	<link id="base-style-responsive" href="<c:url value="/css/style-responsive.css"/>" rel="stylesheet">
	<link href="<c:url value="/css/index.css"/>" rel="stylesheet">
	<link rel="shortcut icon" href="<c:url value="/img/favicon.ico"/>">
	<link href="<c:url value="/css/page.css"/>" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="<c:url value="/css/jquery.datetimepicker.css"/>"/>
	<link href="<c:url value="/css/but.css"/>" rel="stylesheet">
	<script src="<c:url value="/js/jquery-1.9.1.min.js"/>"></script>
	<script src="<c:url value="/js/jquery-migrate-1.0.0.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/layer/layer.js"/>"></script>
	<script src="<c:url value="/js/laydate/laydate.js"/>"></script>
	<script src="<c:url value="/js/build/jquery.datetimepicker.full.js"/>"></script>
</head>
 <script type="text/javascript">
 

 
 var i="${i}";
 
 
 function closebutton() {
	var index = parent.layer.getFrameIndex(window.name);  
 	parent.layer.close(index);  
 }
 


function submitForm(){
	var isNum=/^(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0){1}$)|(^\d\.\d{1,2}?$)/;
	var regs = /\s/;
	var list=document.getElementsByClassName("pay");
	var pay="";
	var l=0;
	for(var j=0;j<list.length;j++){
		if(regs.exec(list[j].value)!=null){
		  alert('不允许输入空格！');
		  return;
		}
		if(l%2==0){
			if(list[j].value==""||list[j].value==null){
				alert("名称不能为空！");
				return;
			}
			pay+=list[j].value+",";
		}else{
			if(list[j].value==""||list[j].value==null){
				alert("金额不能为空！");
				return;
			}
			if(!isNum.exec(list[j].value)){
				alert("请输入正确的金额");
				return;
			}
			pay+=list[j].value+";";
			
		}
		l++;
	}
	$("#pays").val(pay);
	document.forms["frm"].submit();
}

	
function addTr2(tab, row){
	var status=$("input[name=status]:checked ").val(); 
	var type=$("#seletc1").val();
		 if(parseInt(i)<parseInt(5)){
		 	i++;
		    var trHtml="<tr id='trId'>"+
			"<td style='text-align:right;vertical-align:middle;'>"+
			"<input type='hidden' id='seletc1' name='seletc1'  value='1'>"+
				"名称："+
			"</td>"+
			"<td  style='text-align:left;vertical-align:middle;'>"+
				"<input style='margin-bottom:0px;' class='pay' type='text' id='name' name='name' value=''>"+
			"</td>"+
			"<td style='text-align:right;vertical-align:middle;'>金额：</td>"+
			"<td  style='text-align:left;vertical-align:middle;'  >"+
				"<input style='margin-bottom:0px;' class='pay' type='text' id='money' name='money' value='' >"+
				"<a href='#' onclick='removeRow(this)'>"+
					"<img  src='<%=basePath%>img/youlingimg/delete.png'>"+
				"</a>"+
			"</td>"+
		"</tr>";
		    addTr(tab, row, trHtml);
		 }
}

function addTr(tab, row, trHtml){
    //获取table最后一行 $("#tab tr:last")
    //获取table第一行 $("#tab tr").eq(0)
    //获取table倒数第二行 $("#tab tr").eq(-2)
    var $tr=$("#"+tab+" tr").eq(row);
    if($tr.size()==0){
       alert("指定的table id或行数不存在！");
       return;
    }
    $tr.after(trHtml);
 }
	
//删除行
function removeRow(obj){  
	var tr = this.getRowObj(obj);  
	if(tr != null){  
		tr.parentNode.removeChild(tr);  
		i--;
	}  
}  
	
//得到行对象  
function getRowObj(obj){  
	var i = 0;  
	while(obj.tagName.toLowerCase() != "tr"){  
		obj = obj.parentNode;  
		if(obj.tagName.toLowerCase() == "table")return null;  
	}  
	return obj;  
} 
	
	
//动态删除tr中的所有id等于j值的  
function delAllOptions(j){  
	var status=$("input[name=status]:checked ").val(); 
	var radioval=$("#radioval").val();
	if(status!=radioval){
		$("tr[id="+j+"]").remove();
		i=0;
	}
	$("#radioval").val(status);
}  

 </script>
<body>

	<form name="frm" id="frm" method="post" action="<%=basePath%>salaryc/insertSubsidy"  style="width: 700px;">
			<input type="hidden" id="userid" name="userid"  value="${user.id }">
			<input type="hidden" id="pays" name="pays"  value="">
			<div id="content" class="span10" style="width: 100%;">
				<div class="row-fluid content-table">
					<table id="tab" class="table table-striped table-bordered bootstrap-datatable">
					  <tbody>
						<tr>
							<td style="text-align:right;vertical-align:middle;">姓名：</td>
							<td colspan="3"  style="text-align:left;vertical-align:middle;">
								${user.name }
							</td>
						</tr>
						<c:forEach items="${user.sublist }" var="late">
							<tr id="trId">
								<td style="text-align:right;vertical-align:middle;">
								<input type="hidden" id="seletc1" name="seletc1"  value="1">
									名称：
								</td>
								<td  style="text-align:left;vertical-align:middle;">
									<input style="margin-bottom:0px;" class="pay" type="text" id="name" name="name" value="${late.name }">
								</td>
								<td style="text-align:right;vertical-align:middle;">金额：</td>
								<td  style="text-align:left;vertical-align:middle;"  >
									<input style="margin-bottom:0px;" class="pay" type="text" id="money" name="money" value="${late.money }">
									<a href="#" onclick="removeRow(this)">
										<img  src="<%=basePath%>img/youlingimg/delete.png">
									</a>
								</td>
							</tr>
					  	</c:forEach>
						<tr class="content-search" style="text-align: center;">
							<td colspan="5" style="vertical-align:middle;">
								<div>
									<button class="but" type="button" onclick="addTr2('tab',-3);" id="output">增加计薪规则</button>
								</div>
							</td>
						</tr>
						<tr class="content-search" style="text-align: center;vertical-align:middle;">
							<td colspan="5" style="width:100%;">
								<div>
									<button style="background-color:#f55353;" type="button" onclick="closebutton();" id="output1">关闭</button>
									<button class="but" type="button" id="output" onclick="submitForm();">确定</button>
								</div>
							</td>
						</tr>
					  </tbody>
				  </table>            
				</div>	
			</div>
	</form>
</body>
 <script type="text/javascript">
 $(function(){ 
	 var msg="${msg}";
	 if(msg!=null&&msg!=""){
		 alert(msg);
	 }
 }); 

 </script>
</html>
